package net.seratch.taskun;

import java.util.Calendar;
import java.util.List;
import java.util.concurrent.TimeUnit;

import net.seratch.taskun.common.ComponentContainerAdaptor;

/**
 * Taskun Scheduler interface
 * 
 * @author Kazuhiro Sera
 */
public interface Scheduler {

	/**
	 * Initialize this scheduler
	 */
	public void initialize(ComponentContainerAdaptor containerAdaptor);

	/**
	 * Initialize this scheduler and start a scheduler thread.
	 */
	public void start();

	/**
	 * Scheduler is running or not
	 * 
	 * @return result
	 */
	public boolean isRunning();

	/**
	 * Schedule one-time invocation
	 * 
	 * @param runnable
	 *            worker class that implements {@link Runnable} interface
	 * @param scheduledDate
	 *            scheduled date of the invocation
	 */
	public void scheduleOnetime(Runnable runnable, Calendar scheduledDate);

	/**
	 * Schedule interval invocation
	 * 
	 * @param runnable
	 *            worker class that implements {@link Runnable} interface
	 * @param initialScheduledDate
	 *            scheduled date of the initial invocation
	 * @param interval
	 *            invocation interval
	 * @param timeUnit
	 *            {@link TimeUnit}
	 */
	public void scheduleIntervalExecute(Runnable runnable,
			Calendar initialScheduledDate, long interval, TimeUnit timeUnit);

	/**
	 * Schedule by crontab configurations
	 * 
	 * @param runnable
	 *            worker class that implements {@link Runnable} interface
	 * @param crontab
	 *            crontab configurations
	 */
	public void scheduleCronExecute(Runnable runnable, String crontab);

	/**
	 * Set crontab.txt filepath from class path top directory
	 * 
	 * @param crontabFile
	 *            crontabFile
	 */
	public void replaceCrontabFile(String crontabFile);

	/**
	 * Shutdown this scheduler<br>
	 * Interrupt the running workers and cancel all the schedules.
	 */
	public void shutdown();

	/**
	 * Get list of current scheduling string
	 * 
	 * @return scheduling list
	 */
	public List<String> getCurrentSchedulingList();

}
